//
//  DoctorIntrTableView.m
//  HarmonizePub
//
//  Created by zengbinsi_mac_mini on 2016/11/8.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "DoctorIntrTableView.h"
#import "Config.h"
#import "ScheduleTableViewCell.h"

#define labelFont [UIFont systemFontOfSize:13.0f]
static NSString *CellIdentifier = @"Cell";

@interface DoctorIntrTableView () <UITableViewDelegate, UITableViewDataSource, ScheduleTableCellDelegate>
{
    touchItemActionBlock _touchItemActionBlock;
}

@end

@implementation DoctorIntrTableView

- (instancetype)initWithTouchItemAction:(touchItemActionBlock)touchItemActionBlock {
    _touchItemActionBlock = touchItemActionBlock;
    return [self initWithFrame:CGRectZero style:UITableViewStyleGrouped];
}

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    if (self = [super initWithFrame:frame style:style]) {
        self.delegate = self;
        self.dataSource = self;
        self.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        self.contentInset = UIEdgeInsetsMake(10.0f, 0, 0, 0);
        UINib *nib = [UINib nibWithNibName:[ScheduleTableViewCell registerName] bundle:nil];
        [self registerNib:nib forCellReuseIdentifier:CellIdentifier];
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray {
    _dataArray = dataArray;
    [self reloadData];
}

#pragma mark - tableView Delegate/DataSource Method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [ScheduleTableViewCell cellHeight];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (self.type)
        return 20.0f;
    return 0.01f;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (self.type)
        return _dataArray[section][@"ksmc"];
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ScheduleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.delegate = self;
    cell.dataDict = _dataArray[indexPath.section];
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

- (void)tableViewCell:(ScheduleTableViewCell *)tableViewCell didTouchItemWithDataDictionary:(NSDictionary *)dataDict {
    _touchItemActionBlock(dataDict);
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return  nil;
    
}
@end
